package com.util;

import com.hdb.TAdmin;
import com.hdb.TUser;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * Created by aszer on 2016/11/9.
 */
public class Check {
    //分别是读写删的权限
    static List<boolean[]> PermissionList = new ArrayList<>(Arrays.asList(
            new boolean[]{false, false, false}, //userLevel:0
            new boolean[]{true, false, false},
            new boolean[]{true, true, false},
            new boolean[]{true, true, false},
            new boolean[]{true, true, false}, //userLevel:5
            new boolean[]{false, false, false}, //adminLevel:6
            new boolean[]{true, false, false},
            new boolean[]{true, true, false},
            new boolean[]{true, true, true},
            new boolean[]{true, true, true} //adminLevel:10
    ));

    public static TUser user(HttpSession session) {
        if (session == null) return null;
        return (TUser) session.getAttribute("user");
    }

    public static TAdmin admin(HttpSession session) {
        if (session == null) return null;
        return (TAdmin) session.getAttribute("admin");
    }

    public static boolean[] getPermissionArray(int level) {
        return PermissionList.get(level);
    }
}
